<?php

class Module_Impl_Relation_Select extends Module_Impl_Abstarct_Select  {

	protected $_tablename = Config_Table::TABLE_BLOG_TAG_RELATION;	
	protected $_objectname = "Object_Blog_Tag_Relation";
	
	CONST SQLARRAY_OPTION_JOIN_BLOG = 'join_blog';
	CONST SQLARRAY_OPTION_JOIN_TAG = 'join_tag';
	
	/**
	 * Singleton instance
	 * @var Module_Impl_Relation_Select
	 */
	protected static $_instance = null;
	/**
	 * Singleton instance 
	 * @return Module_Impl_Relation_Select
	 */
	public static function getInstance() {
		if (null === self::$_instance) {
			self::$_instance = new self ( );
		}
		return self::$_instance;
	}
	
	
	protected  function _getSqlArray($options = array()) {
		$sqlArray = parent::_getSqlArray($options );
		$options = array_merge($this->_options,$options);	
		
		$_join_tag_info = isset ( $options [self::SQLARRAY_OPTION_JOIN_TAG] ) ? $options [self::SQLARRAY_OPTION_JOIN_TAG] : false;	
		if($_join_tag_info){	
			$sqlArray ['join'] [0] ['tablename'] = Config_Table::TABLE_BLOG_TAG;
			$sqlArray ['join'] [0] ['on'] = Config_Table::TABLE_BLOG_TAG . '.id =' . Config_Table::TABLE_BLOG_TAG_RELATION . '.tag_id';
			$sqlArray ['join'] [0] ['select'] = '*';	
			$this->_objectname = 'Object_Blog_Tag';	
		}
		$_join_blog_info = isset ( $options [self::SQLARRAY_OPTION_JOIN_BLOG] ) ? $options [self::SQLARRAY_OPTION_JOIN_BLOG] : false;	
		if($_join_blog_info){	
			$sqlArray ['join'] [1] ['tablename'] = Config_Table::TABLE_BLOG;
			$sqlArray ['join'] [1] ['on'] = Config_Table::TABLE_BLOG . '.id =' . Config_Table::TABLE_BLOG_TAG_RELATION . '.blog_id';
			$sqlArray ['join'] [1] ['select'] = '*';
			$this->_objectname = 'Object_Blog';	
		}	
		return $sqlArray;
	}
}